package cn.sdormitory.controller.smartdor;

import cn.sdormitory.common.annotation.IgnoreAuth;
import cn.sdormitory.common.api.CommonResult;
import cn.sdormitory.smartdor.entity.AdManualAttence;
import cn.sdormitory.smartdor.entity.SdHygieneStudent;
import cn.sdormitory.smartdor.service.SdStudentHygieneService;
import cn.sdormitory.smartdor.vo.SdAttenceStudentVo;
import cn.sdormitory.smartdor.vo.SdStudentHygieneVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.List;

@RestController
@Api(tags = "Smartdor-studentHygiene=> 学生卫生考核")
@RequestMapping("/smartdor/studentHygiene")
public class SdStudentHygieneController {

    @Resource
    private SdStudentHygieneService sdStudentHygieneService;

    @IgnoreAuth
    @ApiOperation("getStuByCheckDateAndBdormitoryId=>根据卫生检查日期和宿舍ID查询学生信息")
    @GetMapping("/getStuByCheckDateAndBdormitoryId")
    public CommonResult<List<SdStudentHygieneVo>> getStuByCheckDateAndBdormitoryId(String checkDate, String bdormitoryId) {

        //System.out.println("getStuByCheckDateAndBdormitoryId 检查日期： "+checkDate +"\t bdormitoryId :"+bdormitoryId);
        List<SdStudentHygieneVo> studentList = sdStudentHygieneService.getStuByCheckDateAndBdormitoryId(checkDate,Long.parseLong(bdormitoryId));
        return CommonResult.success(studentList);
    }

    @ApiOperation("create => 新增学生卫生考核信息")
    //@PreAuthorize("@ss.hasPermi('smartdor:manualsdattence:add')")
    @IgnoreAuth
    @PostMapping(value = "/create")
    public CommonResult<Integer> create(@RequestBody SdStudentHygieneVo sdStudentHygieneVo) throws IOException {
       // System.out.println(" 新增学生卫生考核信息  :" + sdStudentHygieneVo);
        int count = sdStudentHygieneService.addStudentHygiene(sdStudentHygieneVo);
        if (count > 0) {
            return CommonResult.success(count);
        }
        return CommonResult.failed();

    }
}
